const needle = require('needle');

// let requestHttp = process.env.VITE_DEV_SERVER_URL ? http : https
let baseUrl = process.env.VITE_DEV_SERVER_URL ? 'http://localhost:7004' : 'https://saddress.dizhi666.com'
export async function nodeRequest(method:string='GET',url:string,data:object){
  console.log('nodeRequest:',method,url,data)
  let fUrl = baseUrl + url
  return new Promise(async (resolve)=>{
    needle.post(fUrl,data,(err:any,resp:any)=>{
      if(err){
        console.error(err)
      }
      console.log('resp:',resp.body)
      resolve(resp)
    })
  })

} 
